package com.example.springbootgraduation.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.example.springbootgraduation.entity.Role;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

//角色
public interface RoleMapper extends BaseMapper<Role>{
    @Select("select mid from role_menu where rid = #{roleId}")
    List<Integer> queryMidByRid(Integer roleId);

    //1.分配菜单栏之前删除所有的rid数据
    @Delete("delete from role_menu where rid = #{rid}")
    void deleteRoleByRid(@Param("rid") Integer rid);

    //2.保存分配 角色 与 菜单 的关系
    @Insert("insert into role_menu(rid,mid) values (#{rid},#{mid})")
    void saveRoleMenu(@Param("rid") Integer rid,@Param("mid") Integer mid);

    //1.根据用户查询所有的角色
    @Select("select rid from user_role where uid = #{id}")
    List<Integer> queryUserRoleById(Integer id);

    /*1.先删除之前的用户与角色关系*/
    @Delete("delete from user_role where uid = #{uid}")//根据uid删除所有的数据
    void deleteRoleUserByUid(Integer uid);

    /*2.保存分配的用户与角色之间的关系*/
    @Insert("insert into user_role(uid,rid) values(#{uid},#{rid})")
    void saveUserRole(@Param("uid")Integer uid,@Param("rid") Integer rid);
}
